package io.adrainty.bolee.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.user.UserEntity;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.security.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>UserController</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description UserController
 * @since 2025/8/7 11:54:21
 */

@Tag(name = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private IUserService userService;

    @PutMapping
    @Operation(summary = "创建用户")
    public ResultDTO<UserEntity> createUser(@RequestBody UserEntity userEntity) {
        UserEntity createResult = userService.createUser(userEntity);
        return ResultDTOUtil.success(createResult);
    }

    @PostMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "分页获取用户")
    public ResultDTO<IPage<UserEntity>> findUserPage(@RequestBody UserEntity entity,
                                                     @PathVariable("pageNum") Integer pageNum,
                                                     @PathVariable("pageSize") Integer pageSize) {
        IPage<UserEntity> pageResult = userService.findUserPage(entity, pageNum, pageSize);
        return ResultDTOUtil.success(pageResult);
    }

    @PatchMapping
    @Operation(summary = "用户修改")
    public ResultDTO<UserEntity> updateUser(@RequestBody UserEntity entity) {
        UserEntity result = userService.updateUser(entity);
        return ResultDTOUtil.success(result);
    }

    @PostMapping("list")
    @Operation(summary = "用户列表")
    public ResultDTO<List<UserEntity>> listUser(@RequestBody UserEntity entity) {
        List<UserEntity> result = userService.listUser(entity);
        return ResultDTOUtil.success(result);
    }

}
